/**
 * RevenueSourceFactory.java
 * Created on April 12, 2007, 4:59 PM
 *
 *
 */

package edu.byu.isys413.jjenkins.data;

import java.util.Map;
import java.util.TreeMap;

/**
 * This class contans a tree map and it acts as a intermediate between dao's
 * @author Jeff Jenkins
 * @version 1.0
 */
public class RevenueSourceFactory {
    
    /**
     * list of revenue source factories
     */
    Map factory;
    
    private static RevenueSourceFactory instance = null;
    
    /** Creates a new instance of RevenueSourceFactory*/
    private RevenueSourceFactory() {
        
        factory = new TreeMap();
        //factory.put("example", ExampleSubRevSourceDAO.getInstance());
        
        factory.put("backup",BackupDAO.getInstance());
        factory.put("service_repair",ServiceRepairDAO.getInstance());
        factory.put("sale", SaleDAO.getInstance());
        factory.put("rental", RentalDAO.getInstance());
        factory.put("fee", FeeDAO.getInstance());
        factory.put("print_order", PrintOrderLineRSDAO.getInstance());
        factory.put("conversion", ConversionDAO.getInstance());
        /*TODO add the other revenuesources */
        
    }
    
    /*This mehod ensures that only one instance of revenueSourceFactory
     *exists */
    
    /**
     * gets an instance of the revenue source factory
     * @return revenuesourcefacotry
     */
    public static synchronized RevenueSourceFactory getInstance() {
        if (instance == null) {
            instance = new RevenueSourceFactory();
        }
        return instance;
    }
    
    /*This method returns the appropriate sub revenuesourceDAO based on the
     *string that is passed in
     *
     *@param String name of the revenue soruce
     */
    
    /**
     * gets the dao that correspons with a type
     * @param name type of dao
     * @return
     */
    public RevenueSourceDAO getDAO(String name){
        
        return (RevenueSourceDAO)factory.get(name);
    }
}
